package myschool.web;

import myschool.biz.GradeService;
import myschool.entity.Grade;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(name = "GradeServlet", value = {"/grade","/grade2.jsp"})
public class GradeServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
            IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
            IOException {
        List<Grade> all = GradeService.ME.findAll();
        request.setAttribute("grades",all);
        request.getRequestDispatcher("grades.jsp").forward(request,response);
//        response.setContentType("text/html;charset=utf-8");
//        PrintWriter writer = response.getWriter();
//        writer.write("<html>");
//        writer.write("<head>");
//        writer.write("<style>");
//        writer.write("p{font-size:45px;color:gold;border-bottom:2px solid red;}");
//        writer.write("</style>");
//        writer.write("</head>");
//        writer.write("<body>");
//        all.forEach(x->{
//            writer.write("<p>");
//            writer.write(x.getId()+"--"+x.getGname());
//            writer.write("</p>");
//        });
//
//        writer.write("</body>");
//        writer.write("</html>");
    }
}
